<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://s3.pstatp.com/cdn/expire-1-M/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<div id="box">
    <form>
        <input type="text" name="user" value="">
        <input type="password" name="password">
        <button type="button" id="buton">提交</button>
    </form>
</div>
</body>
<script>
    $(function (){
        $('#buton').click(function (){
            var name = $('input[name="user"]').val();
            var password = $('input[name="password"]').val();
            if(name==""||password==""){
                alert("内容不能为空")
                return  false;
            }
            $.ajax({
                url:"http://localhost/login.php",
                type:"post",
                data:{name:name,pass:password},
                dataType:"json",
                success:function (res){
                    if(res.status==200){
                        alert(res.msg);
                        window.location = "/main.php?token=xxxx"
                    }else {
                        alert(res.msg);
                    }
                },
                error:function (){
                    alert("请求失败")
                }
            })
        })
    })
    $(function (){

    })
</script>
</html>